/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sfsBeans;

import EL.ReservationDetails;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.ejb.Stateful;

/**
 *
 * @author Tian
 */
@Stateful
public class ReservationContractBLO implements ReservationContractBLORemote {
    
    private ArrayList<ReservationDetails> contract;
    @PostConstruct
    public void init()
    {
        contract = new ArrayList<ReservationDetails>();
    }

    public void addTable2Contract(ReservationDetails reservationDetails)
    {
        if(contract.contains(reservationDetails))
        {

            ReservationDetails reserveDetail = contract.get(contract.indexOf(reservationDetails));
            reserveDetail.setQuantity(reserveDetail.getQuantity() + reservationDetails.getQuantity());
        }
        else
        {

            contract.add(reservationDetails);
        }
    }

    public ArrayList<ReservationDetails> viewContract()
    {
        return contract;
    }

    public void remove(ReservationDetails reserveDetail)
    {
        contract.remove(reserveDetail);
    }

    public void update(ReservationDetails reservationDetails)
    {
        if(contract.contains(reservationDetails))
        {

            ReservationDetails reserveDetail = contract.get(contract.indexOf(reservationDetails));
            reserveDetail.setQuantity(0);
            reserveDetail.setQuantity(reservationDetails.getQuantity());
        }
        else
        {

            contract.add(reservationDetails);
        }
    }
    
}
